/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

/*
 * date.java
 *
 * Created on Jul 15, 2013, 7:03:35 PM
 */
package homework;

/**
 *
 * @author ASUS K43E
 */
public class date extends javax.swing.JFrame {

    /** Creates new form date */
    public date() {
        initComponents();
        this.setSize(350, 140);
    }

    public int validDate(int d, int m, int y) {
        int maxd = 31;
        if (d < 1 || d > 31 || m < 1 || m > 12) {
            return 0;
        }
        if (m == 4 || m == 6 || m == 9 || m == 11) {
            maxd = 30;
        } else if (m == 2) {
            if (y % 400 == 0 || y % 4 == 0 && y % 100 != 0) {
                maxd = 29;
            } else {
                maxd = 28;
            }
        }
        if (d <= maxd) {
            return 1;
        }
        return 0;
    }

    /** This method is called from within the constructor to
     * initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is
     * always regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        jLabel1 = new javax.swing.JLabel();
        txtDay = new javax.swing.JTextField();
        txtMonth = new javax.swing.JTextField();
        jLabel2 = new javax.swing.JLabel();
        txtYear = new javax.swing.JTextField();
        jLabel3 = new javax.swing.JLabel();
        btnResult = new javax.swing.JButton();
        txtResult = new javax.swing.JLabel();

        setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
        getContentPane().setLayout(null);

        jLabel1.setText("Day:");
        getContentPane().add(jLabel1);
        jLabel1.setBounds(10, 20, 34, 14);
        getContentPane().add(txtDay);
        txtDay.setBounds(40, 20, 40, 20);
        getContentPane().add(txtMonth);
        txtMonth.setBounds(150, 20, 40, 20);

        jLabel2.setText("Month:");
        getContentPane().add(jLabel2);
        jLabel2.setBounds(100, 20, 50, 14);
        getContentPane().add(txtYear);
        txtYear.setBounds(250, 20, 70, 20);

        jLabel3.setText("Year:");
        getContentPane().add(jLabel3);
        jLabel3.setBounds(210, 20, 34, 14);

        btnResult.setText("Result");
        btnResult.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btnResultActionPerformed(evt);
            }
        });
        getContentPane().add(btnResult);
        btnResult.setBounds(10, 60, 80, 23);

        txtResult.setBackground(new java.awt.Color(153, 255, 255));
        txtResult.setForeground(new java.awt.Color(255, 0, 0));
        getContentPane().add(txtResult);
        txtResult.setBounds(120, 60, 180, 20);

        pack();
    }// </editor-fold>//GEN-END:initComponents

    private void btnResultActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnResultActionPerformed
        // TODO add your handling code here:
        int d = Integer.parseInt(txtDay.getText());
        int m = Integer.parseInt(txtMonth.getText());
        int y = Integer.parseInt(txtYear.getText());
        if (validDate(d, m, y) == 0) {
            txtResult.setText("Invalid date");
        } else {
            txtResult.setText("Valid date");
        }
    }//GEN-LAST:event_btnResultActionPerformed

    /**
     * @param args the command line arguments
     */
    public static void main(String args[]) {
        java.awt.EventQueue.invokeLater(new Runnable() {

            public void run() {
                new date().setVisible(true);
            }
        });
    }
    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JButton btnResult;
    private javax.swing.JLabel jLabel1;
    private javax.swing.JLabel jLabel2;
    private javax.swing.JLabel jLabel3;
    private javax.swing.JTextField txtDay;
    private javax.swing.JTextField txtMonth;
    private javax.swing.JLabel txtResult;
    private javax.swing.JTextField txtYear;
    // End of variables declaration//GEN-END:variables
}
